// pages/hotelinfo/hotelinfo.js
var Data = require("../../utils/data.js");

Page({
  data: {
    is_select_Hidden: true,
    is_modal_Msg: '我是一个自定义组件',
    date: '',
    tomorrow: '',
    dates: 2,
    roomnum: 1
  },
  onShow: function () {
    // 页面显示
    var startDate = wx.getStorageSync("startDate");
    var endDate = wx.getStorageSync("endDate");
    console.log("初始时间>>>" + startDate + endDate);

    if (!startDate || startDate == '' || !endDate || endDate == '') {
      //初始化当前时间
      // wx.clearStorageSync();
      startDate = Data.formatDate(new Date(), "yyyy-MM-dd");
      wx.setStorageSync("startDate", startDate);
      var tomorrow1 = new Date();
      tomorrow1.setDate((new Date()).getDate() + 1);
      var tomorrow = Data.formatDate(new Date(tomorrow1), "yyyy-MM-dd");
      endDate = tomorrow;
      wx.setStorageSync("endDate", tomorrow);
      console.log("如果为空，计算后时间>>>" + startDate + endDate);
    }

    var aDate, oDate1, oDate2, iDays
    aDate = endDate.split("-")
    console.log("aDate>>>:length-" + aDate.length + ",0-" + aDate[0] + ",1-" + aDate[1] + ",2-" + aDate[2])
    oDate1 = new Date();
    oDate1.setFullYear(aDate[0]);
    oDate1.setMonth(aDate[1] - 1);
    oDate1.setDate(aDate[2]);

    aDate = startDate.split("-")
    oDate2 = new Date();
    oDate2.setFullYear(aDate[0]);
    oDate2.setMonth(aDate[1] - 1);
    oDate2.setDate(aDate[2]);
    console.log("oDate2》》》", oDate2)
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)    //把相差的毫秒数转换为天数  
    console.log("iDays》》》", iDays);
    this.setData({
      date: startDate,
      tomorrow: endDate,
      dates: iDays
    });
  },
  //事件处理函数
  bindViewTap: function () {
    var that = this;
    var startDate = that.data.date;
    var endDate = that.data.tomorrow;
    wx.navigateTo({
      url: '../calender/index?startDate=' + startDate + "&endDate=" + endDate
    })
  },
  selectCity: function () {
    wx.navigateTo({
      url: ''
    })
  } ,
  sliderChange: function (e) {
    this.setData({
      price: (e.detail.value === 600 ? '不限' : e.detail.value)
    })
  },
  complete: function () {
    this.setData({
      is_select_Hidden: true
    });
  },
  add: function () {
    var that = this;
    var addRoom = that.data.roomnum;
    this.setData({
      roomnum: addRoom+1
    })
  },
  sub: function () {
    var that = this;
    var addRoom = that.data.roomnum;
    if (addRoom>1) {
      this.setData({
        roomnum: addRoom - 1
      })
    }
    
  }
})